<?php
namespace Tyrone\Model;
use Medoo\Medoo;

class PlayerPay extends Base
{
    protected $table = OLD_CENTER_DB.'.l_player_pay';


    public function statPay($payMap = array())
    {
        //return $this->statPay2($payMap);

        return $this->database->select("{$this->table}(p)",[
            '[><]'.OLD_CENTER_DB.'.l_player(r)' => [
                'p.player_id' => 'player_id',
                'p.platform' =>'platform',
                'p.plat_server' =>'plat_server',
                ]
        ],[
            'p.platform',
            'p.plat_server',
            'rmb' => Medoo::raw('SUM(p.rmb)'),
            'num' => Medoo::raw('COUNT(p.id)'),
            'players' => Medoo::raw('COUNT(DISTINCT p.player_id)'),
        ], $payMap + [
                'GROUP' => ['p.platform','p.plat_server'],
            ]
        );
    }

    public function statPay2($payMap = array())
    {
        return $this->database->select("{$this->table}(p)",[
            'p.platform',
            'rmb' => Medoo::raw('SUM(p.rmb)'),
            'num' => Medoo::raw('COUNT(p.id)'),
            'players' => Medoo::raw('COUNT(DISTINCT p.player_id)'),
        ], $payMap + [
                'GROUP' => ['p.platform','p.plat_server'],
            ]
        );
    }

    public function getRoleGroupData($day = null,$where = []){
        if($day){
            $where['pay_date'] = $day;
        }
        $list =  $this->database->select($this->table,[
            'rmb' =>Medoo::raw('SUM(rmb)'),
            'player_id',
        ],$where + [
                'GROUP' => 'player_id'
            ]);
        return array_column($list,null,'player_id');
    }






}